import { PageParam } from '@/services/common'
import { covertTableData } from '@/utils/tableUtil'
import { request } from '@umijs/max'

export interface DeliverLogVO {
  /**
   * 渠道id
   */
  channelId: string
  /**
   * 创建时间
   */
  createTime: string
  /**
   * 创建者
   */
  creator: string
  /**
   * 是否删除
   */
  deleted: string
  /**
   * 投放时间
   */
  deliverTime: string
  /**
   * 本次花费
   */
  fee: number
  /**
   * 编号
   */
  id: string
  /**
   * 租户id
   */
  tenantId: string
  /**
   * 更新者
   */
  updater: string
  /**
   * 更新时间
   */
  updateTime: string
}

export interface DeliverLogQueryDTO extends PageParam {
  /**
   * 编号
   */
  id: string
}

export interface DeliverLogUpdateDTO {
  /**
   * 渠道id
   */
  channelId?: string
  /**
   * 创建时间
   */
  createTime?: string
  /**
   * 创建者
   */
  creator?: string
  /**
   * 是否删除
   */
  deleted?: string
  /**
   * 投放时间
   */
  deliverTime?: string
  /**
   * 本次花费
   */
  fee: number
  /**
   * 编号
   */
  id?: string
  /**
   * 租户id
   */
  tenantId?: string
  /**
   * 更新者
   */
  updater?: string
  /**
   * 更新时间
   */
  updateTime?: string
}

export const getDeliverLogById = async (id: string) => {
  return request<DeliverLogVO>(`/api/v2/deliverLog?id=${id}`, { method: 'GET' })
}

export const getDeliverLogList = async (params: DeliverLogQueryDTO) => {
  return request<Array<DeliverLogVO>>(`/api/v2/deliverLog/deliverLogList`, { method: 'GET', params })
}

export const getDeliverLogPage = async (params: DeliverLogQueryDTO) => {
  let response = await request<Array<DeliverLogVO>>(`/api/v2/deliverLog/deliverLogPage`, { method: 'GET', params })
  return covertTableData(response)
}

export const updateDeliverLog = async (deliverLogUpdateDTO: DeliverLogUpdateDTO) => {
  return request<DeliverLogVO>(`/api/v2/deliverLog/editDeliverLog`, { method: 'POST', data: deliverLogUpdateDTO })
}

export const saveDeliverLog = async (deliverLogUpdateDTO: DeliverLogUpdateDTO) => {
  return request<DeliverLogVO>(`/api/v2/deliverLog/addDeliverLog`, { method: 'POST', data: deliverLogUpdateDTO })
}

export const removeDeliverLog = async (idList: string[]) => {
  return request<boolean>(`/api/v2/deliverLog/removeDeliverLog?idList=${idList}`, { method: 'POST' })
}
